<html>
<head><meta charset="utf-8"><title>How to understand &amp;**&amp;Vec[T]? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20understand.20.26**.26Vec.5BT.5D.3F.html">How to understand &amp;**&amp;Vec[T]?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="172822563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20understand%20%26%2A%2A%26Vec%5BT%5D%3F/near/172822563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yan Luo <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20understand.20.26**.26Vec.5BT.5D.3F.html#172822563">(Aug 09 2019 at 03:36)</a>:</h4>
<p>Hello, I am reading the Clone implementation for Vec[T] in <a href="http://vec.rs" target="_blank" title="http://vec.rs">vec.rs</a>.  In the implementation of the Clone trait for Vec[T],  the "clone" fn is like:<br>
fn clone(&amp;self) -&gt; Vec[T] {<br>
  &lt;[T]&gt;::to_vec(&amp;**self)<br>
}<br>
In my understanding, self here is a reference. *self is still a reference to Vec[T], and **self is also a reference to Vec[T] because Deref for &amp;T returns &amp;T. Why are there 2 deref?</p>
<p>Thanks!</p>



<a name="173936369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20understand%20%26%2A%2A%26Vec%5BT%5D%3F/near/173936369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nick12 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20understand.20.26**.26Vec.5BT.5D.3F.html#173936369">(Aug 23 2019 at 02:03)</a>:</h4>
<p>**self just dereferences self twice, once to go from &amp;Vec to Vec, and once more, I assume to use the Deref impl to go to a [T]. Then it takes a ref, making it a slice, and calls slice::to_vec on it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>